package cn.chenwx.bbsforum.mapper;

import cn.chenwx.bbsforum.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Mapper
@Repository
public interface CommentMapper {
    // 通过文章的id查找到评论的数量
    @Select("select count(1) from comment where articleId=#{id}")
    int findCommentsByArticleId(@Param("id") int id);
    @Select("select content from comment where articleId=#{id}")
    @Results(id = "comment",
            value={
                    @Result(id = true, property = "id", column = "id"),
                    @Result(property = "createTime", column = "createTime"),
                    @Result(property = "articleId", column = "answererId")

            })
    List<Comment> findContentByArticleId(@Param("id") int id);
    @Select("select * from comment where articleId=#{id}")
    @Results(
            {
                    @Result(id = true, property = "id", column = "id"),
                    @Result(property = "createTime", column = "createTime"),
                    @Result(property = "answererId", column = "answererId")

            })
    List<Comment> findAllByArticleId(@Param("id") int id);

    // 根据评论的id删除
    @Delete("delete from comment where id=#{id}")
    int deleteContentById(@Param("id") int id);
    @Select("select * from comment")
    List<Comment> getAllComment();
    @Select("select count(1) from comment")
    int getAllComments();
    @Select("select * from comment where answererId=#{userId}")
    List<Comment> getUserCommentByRespondentId(@Param("userId") int userId);
    @Select("select count(*) from comment where answererId=#{userId}")
    int countIsReadNumByRespondentId(@Param("userId") int userId);
    @Insert("insert into comment(content,articleId,answererId) values(#{content},#{articleId},#{answererId})")
    int insertComment(Comment comment);
}
